﻿using T4UtilityBelt.DataDesigns;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Controls.Renderers.Windows
{
    public class EnumRenderer : PropertyRenderer<EnumControl, IEnumRenderer, EnumProperty>, IEnumRenderer
    {
        protected override void OnRenderUiXmlContentInput(EnumControl control, CodeWriter writer)
        {
            //<ComboBox Controls:HelpText.Text="<#=name#>tt" ItemsSource="{Binding <#=name#>List}"
            //          SelectedItem="{Binding Entry.<#=name#>, Mode=TwoWay}" />
            writer.WriteBeginTag("ComboBox");

            RenderControlAttributes(control, writer);

            //writer.WriteAttribute("ItemsSource", string.Format(@"{{Binding {0}List}}", control.PropertyName));
            //writer.WriteAttribute("SelectedItem", string.Format(@"{{Binding {0},  Mode=TwoWay}}", GetBindingContext(control)));

            writer.WriteFullEnd();
        }
         
        protected override void OnRenderUiXmlContentReadOnly(EnumControl control, CodeWriter writer)
        {
            //<TextBlock  Text="{Binding  Entry.<#=name#>}" />
            writer.WriteBeginTag("TextBlock");
            if (control.Style == null)
            {
                writer.WriteAttribute("Style", "{StaticResource ReadonlyTextBlock}");
            }
            else
            {
                writer.WriteAttributeFormat("Style", @"{{StaticResource {0}}}", control.Style);
            }
            //writer.WriteAttribute("Text", string.Format(@"{{Binding {0}, Converter={{StaticResource translateEnum}}}}", GetBindingContext(control)));

            writer.WriteFullEnd();
        }

        protected override void OnRenderViewModelCs(EnumControl control, CodeWriter writer)
        {
            writer.WriteFormatLine(
@"      public Array {0}List
        {{
            get
            {{
                return Enum.GetValues(typeof({1}));
            }}
        }}
",
            control.PropertyName, control.Property.PropertyType
);
        }
    }
}